<!--
 * @Descripttion: your project
 * @version: 1.0
 * @Author: hongweixun
 * @Date: 2023-05-17 16:06:06
 * @LastEditors: liyin 2179253556@qq.com
 * @LastEditTime: 2025-08-29 16:54:11
-->
<template>
  <div class="ranking-handle-box">
    <Title :isbig="true">
      <template #title>
        各学校缴费排名
      </template>
      <template #info>
        <span @click="selectActive(1)" :class="currentIndex == 1 ? 'active' : ''">总办理率</span>
        <span @click="selectActive(2)" :class="currentIndex == 2 ? 'active' : ''">续办率</span>
        <span @click="selectActive(3)" :class="currentIndex == 3 ? 'active' : ''">新生办理率</span>
      </template>
    </Title>
    <!-- 排行 -->
    <div class="contentBox" v-if="listThree.length > 0 || listTwo.length > 0 || listOne.length > 0">
      <el-row :gutter="24" class="listBox" style="padding: 0 12px;">
        <el-col :span="12"
          v-for="(item, index) in currentIndex == 1 ? listOne.slice((pageQuery.page - 1) * 2, pageQuery.page * 2) : currentIndex == 2 ? listTwo.slice((pageQuery.page - 1) * 2, pageQuery.page * 2) : listThree.slice((pageQuery.page - 1) * 2, pageQuery.page * 2)"
          :key="index">
          <div class="column">
            <template v-for="(k, i) in item" :key="index">
              <div class="row common-ranking-box" :class="{
                'one-bg-box': index == 0 && i == 0 && pageQuery.page == 1,
                'two-bg-box': index == 0 && i == 1 && pageQuery.page == 1,
                'three-bg-box':
                  index == 0 && i == 2 && pageQuery.page == 1
              }">
                <el-row class="level-common-box">{{
                  index * 7 + (i + 1) + (pageQuery.page - 1) * 14
                  }}</el-row>
                <el-row class="common-row-list-box" type="flex" justify="space-between">
                  <el-col :span="18" class="school-name-box">{{
                    k.school_name ? k.school_name : '宏联测试学校'
                    }}</el-col>
                  <el-col :span="6" style="text-align: right;">
                    <span>{{ currentIndex == 1 ? k.payment_rate : currentIndex == 2 ? k.payment_renew_rate :
                      k.payment_newer_rate }}%</span>
                  </el-col>
                </el-row>
                <el-popover placement="bottom" :title="k.school_name" :width="300" trigger="hover" content="">
                  <template #reference>
                    <div class="show-Btn" @click="toChioce(k)">
                      {{ index * 7 + (i + 1) + (pageQuery.page - 1) * 14 }}
                    </div>
                  </template>
                  <template #default>
                    <el-row style="margin-bottom: 10px;">
                      <el-col :span="18">
                        学生总数量
                      </el-col>
                      <el-col :span="6" style="text-align:right">
                        {{ k.student_count + '人' }}
                      </el-col>
                    </el-row>
                    <el-row style="margin-bottom: 10px;">
                      <el-col :span="18">
                        新生总数量
                      </el-col>
                      <el-col :span="6" style="text-align:right">
                        {{ k.new_student_count + '人' }}
                      </el-col>
                    </el-row>
                    <el-row style="margin-bottom: 10px;">
                      <el-col :span="14">
                        缴费总额
                      </el-col>
                      <el-col :span="10" style="text-align:right">
                        {{ k.payment_total_amount + '元' }}
                      </el-col>
                    </el-row>
                    <el-row style="margin-bottom: 10px;">
                      <el-col :span="18">
                        缴费总数
                      </el-col>
                      <el-col :span="6" style="text-align:right">
                        {{ k.payment_total_count + '人' }}
                      </el-col>
                    </el-row>
                    <el-row style="margin-bottom: 10px;">
                      <el-col :span="18">
                        总办理率
                      </el-col>
                      <el-col :span="6" style="text-align:right">
                        {{ k.payment_rate + '%' }}
                      </el-col>
                    </el-row>
                    <el-row style="margin-bottom: 10px;">
                      <el-col :span="14">
                        新生缴费总额
                      </el-col>
                      <el-col :span="10" style="text-align:right">
                        {{ k.payment_newer_amount + '元' }}
                      </el-col>
                    </el-row>
                    <el-row style="margin-bottom: 10px;">
                      <el-col :span="18">
                        新生缴费总数
                      </el-col>
                      <el-col :span="6" style="text-align:right">
                        {{ k.payment_newer_count + '人' }}
                      </el-col>
                    </el-row>
                    <el-row style="margin-bottom: 10px;">
                      <el-col :span="18">
                        新生办理率
                      </el-col>
                      <el-col :span="6" style="text-align:right">
                        {{ k.payment_newer_rate + '%' }}
                      </el-col>
                    </el-row>
                    <el-row style="margin-bottom: 10px;">
                      <el-col :span="14">
                        续办总额
                      </el-col>
                      <el-col :span="10" style="text-align:right">
                        {{ k.payment_renew_amount + '元' }}
                      </el-col>
                    </el-row>
                    <el-row style="margin-bottom: 10px;">
                      <el-col :span="18">
                        续办总数
                      </el-col>
                      <el-col :span="6" style="text-align:right">
                        {{ k.payment_renew_count + '人' }}
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="18">
                        续办率
                      </el-col>
                      <el-col :span="6" style="text-align:right">
                        {{ k.payment_renew_rate + '%' }}
                      </el-col>
                    </el-row>
                  </template>
                </el-popover>
              </div>
            </template>
          </div>
        </el-col>
      </el-row>
      <el-row class="page-row-box" type="flex" justify="center">
        <el-pagination background v-model:current-page="pageQuery.page" :page-size="pageQuery.page_size" layout="pager"
          :total="total" @current-change="currentChange">
        </el-pagination>
      </el-row>
    </div>
    <NoDate v-if="listThree.length == 0" title="暂无数据"></NoDate>
  </div>
</template>
<script lang="ts" setup>
import { chunk } from 'lodash'
import { PiniaStore } from '../store/index'
import { ref, onMounted } from 'vue'
import { schoolRank } from './Options/Api'
const store = PiniaStore()
interface PropsType {
    startDate?: string
    endDate?: string
    verify_code?: string
}
const props = withDefaults(defineProps<PropsType>(), {
    startDate: '',
    endDate: '',
    verify_code: ''
})
const pageQuery = ref<any>({
  page: 1,
  page_size: 14
})
const total = ref<any>(0)
const currentIndex = ref<number>(3)
const selectActive = (val: any) => {
  currentIndex.value = val
  pageQuery.value.page = 1
}
const currentChange = (val: any) => {
  pageQuery.value.page = val
  getList()
}
const toChioce = (row: any) => {
  // console.log(row)
  const id = row.school_id
  console.log(id)
  store.payStatistics.list.forEach((item: any) => {
    if (item.school_id === id) {
      store.setSchoolStatistics(item)
    }
  })
}
const listOne = ref<any>([])
const listTwo = ref<any>([])
const listThree = ref<any>([])
const getList = async () => {
  const params: any = {
    start_date: props.startDate,
    end_date: props.endDate,
    verify_code: props.verify_code
  }
  const res: any = await schoolRank(params)
  if (res.code !== 1) return false
  return new Promise(async (resolve) => {
    total.value = res.data.payment_newer_rate.length
    listOne.value = chunk(res.data.payment_rate, 7)
    listTwo.value = chunk(res.data.payment_renew_rate, 7)
    listThree.value = chunk(res.data.payment_newer_rate, 7)
    store.setLoddingStatus()
    resolve(undefined) // 所有操作完成后resolve
  })
}
onMounted(() => {
  // getHandleRatio()
})
defineExpose({ getList })
</script>
<style lang="scss" scoped>
.ranking-handle-box {
  height: 474px;
  padding-bottom: 26px;
  position: relative;
}
.listBox {
  margin-top: 24px;
  height: 322px;

  .is-guttered:last-of-type {
    padding-right: 0px !important;
  }
}

.page-row-box {
  padding: 14px 0;
}

.level-common-box {
  width: 34px;
  height: 34px;
  background-color: #0a3c84;
  color: #fff;
  font-size: 14px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 2px 2px 2px 2px;
}

.common-row-list-box {
  flex: 1;
  height: 34px;
  padding: 0 10px;
  box-sizing: border-box;
  background-color: rgba(7, 77, 183, 0.2);
  color: #fff;
  font-size: 14px;
  display: flex;
  align-items: center;
  cursor: pointer;

  span {
    display: inline-block;
    margin-left: 10px;
    color: #00FCFF;
  }
}

.one-bg-box {
  .level-common-box {
    background-color: #fca12f;
  }

  .school-name-box {
    color: #fca12f;
  }
}

.two-bg-box {
  .level-common-box {
    background-color: #49d26d;
  }

  .school-name-box {
    color: #49d26d;
  }
}

.three-bg-box {
  .level-common-box {
    background-color: #5fd5ec;
  }

  .school-name-box {
    color: #5fd5ec;
  }
}

.common-ranking-box {
  position: relative;
  margin-bottom: 12px;
  display: flex;
  align-items: center;

  .show-Btn {
    width: 100%;
    position: absolute;
    left: 0;
    height: 100%;
    z-index: 2;
    opacity: 0;
    cursor: pointer;
  }
}
</style>
<style lang="scss">
.el-pagination.is-background .el-pager li.is-active {
  background-color: #007fff;
  border: 1px solid #007fff;
}

.el-pagination.is-background .el-pager li {
  background-color: transparent;
  border: 1px solid #4b5c91;
}
</style>
